	function add_to_list( chk_name,hdn_id )
	{
		hdn_object = document.getElementById(hdn_id);
		hdn_object.value = "";
		arr_chk = document.getElementsByName(chk_name);
		p=0;
		for (i=0;i<arr_chk.length;i++){
			if (arr_chk[i].checked){
				if (p==0)
				{
					hdn_object.value = arr_chk[i].value;
				}
				else
				{
					hdn_object.value = hdn_object.value+";"+arr_chk[i].value;				
				}
				p++;
			}
		}
	}
	function check_all( chk_name,value )
	{
		arr_chk = document.getElementsByName(chk_name);
		for (i=0;i<arr_chk.length;i++){
			arr_chk[i].checked = value;
		}
	}
	function format_number( input )
	{
		var num = input.value.replace(/\,/g,'');
		if(!isNaN(num))
		{
			if(num.indexOf('.') > -1)
			{
				num = num.split('.');
		        num[0] = num[0].toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1,').split('').reverse().join('').replace(/^[\,]/,'');
		       	if(num[1].length > 2)
			    {
		          alert('Khong the nhap 2 dau thap phan cach!');
		          num[1] = num[1].substring(0,num[1].length-1);
		       	}  
		       	input.value = num[0]+'.'+num[1];        
		     } 
		     else
			 { 
				 input.value = num.toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1,').split('').reverse().join('').replace(/^[\,]/,'') 
			 };
		}
		else
		{ 
			alert('Khong the nhap 2 dau thap phan!');
		         input.value = input.value.substring(0,input.value.length-1);
		}
	}

	function showError( object , error_message )
	{
		focusObject(object);
		humane.error(error_message);
	}

	function isEmptyTextBox( object , error_message )
	{
		value = object.val();
		if ( $.trim(value) == '' || value == 0 )
		{
			if ( error_message != ''){
				showError( object , error_message );
				return true;
			}
		}
		return false;
	}

	function isValidEmail( object, error_message )
	{
		var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		
		var subj = $.trim(object.val());
		subj = subj.replace(/(\"|\')/gi, "");
		if(!subj.match(reg) || subj == '')
		{
			showError(object, error_message);
			return false;
		}
		return true;
	}

	function isValidUserName( object, error_message )
	{
		var reg = /^([a-zA-Z0-9_\.])+$/;
		
		var subj = $.trim(object.val());
		
		if(!subj.match(reg) || subj == '')
		{
			showError(object, error_message);
			return false;
		}
		
		return true;
	}

	/**
	 * @param str_agrs can be array or string
	 */
	function callAjaxFunction( link, str_agrs )
	{
    	var ret = '';
    	var params = "";
    	$.each( str_agrs , function(k, v){
		    	params = params + '&' + k + '='	+ v;
		});

	    $.ajax({
	        url: link + params,
	        cache: false,
	        async: false,
	        success: function(result) {
	        	ret = result;
	        	
	        }
	    });
	    return ret;
    }
    
    function showErrorInline( object , error_message )
    {
    	var html = '<div class="error" style = "display:none">' + error_message + '</div>';
    	object.parent().append(html);
    	object.parent().children(':last-child').fadeIn();
    }

    function focusObject( object )
    {
    	
    	var obj_pos = object.position();
    	if ( obj_pos ){
	    	$('body,html').animate({
				scrollTop: obj_pos.top - 50
			}, 800);
			object.focus();
		}
    }

    function resize( image_id )
    {
		var img_obj = $('#'+image_id);
		var max_size = 150;
		obj_h = img_obj.height();
		obj_w = img_obj.width();
		
		if (img_obj.height() > img_obj.width()) {
			var h = max_size;
			var w = Math.ceil(img_obj.width() / img_obj.height() * max_size);
		} else {
			var w = max_size;
			var h = Math.ceil(img_obj.height() / img_obj.width() * max_size);
		}
		img_obj.css({ height: h, width: w });

	}

	function showEdit( obj_id )
	{
		$('#dsp_'+obj_id).fadeOut();
		$('#btn_show_'+obj_id).fadeOut();
		$('#edit_'+obj_id).fadeIn();
		$('#btn_back'+obj_id).fadeIn();
	}
	
	function hideEdit( obj_id )
	{
		$('#dsp_'+obj_id).fadeIn();
		$('#btn_show_'+obj_id).fadeIn();
		$('#edit_'+obj_id).fadeOut();
		$('#btn_back'+obj_id).fadeOut();
	}

	function displayLongText( string, maxLength )
	{
		if( string != '' && maxLength > 0 )
		{
			//trim the string to the maximum length
			var trimmedString = string.substr(0, maxLength);
			if( string.length > maxLength )
				return trimmedString + '...';
			return trimmedString;
		}
		return string;
	}

	function explode( delimiter, string, limit ) 
	{
	    // http://kevin.vanzonneveld.net
	    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	    // +     improved by: kenneth
	    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	    // +     improved by: d3x
	    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	    // *     example 1: explode(' ', 'Kevin van Zonneveld');
	    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
	    // *     example 2: explode('=', 'a=bc=d', 2);
	    // *     returns 2: ['a', 'bc=d']

	    var emptyArray = {0: ''};

	    // third argument is not required
	    if ( arguments.length < 2 ||
	        typeof arguments[0] == 'undefined' ||
	        typeof arguments[1] == 'undefined' ) {
	        return null;
	    }

	    if ( delimiter === '' ||
	        delimiter === false ||
	        delimiter === null ) {
	        return false;
	    }

	    if ( typeof delimiter == 'function' ||
	        typeof delimiter == 'object' ||
	        typeof string == 'function' ||
	        typeof string == 'object' ) {
	        return emptyArray;
	    }

	    if ( delimiter === true ) {
	        delimiter = '1';
	    }

	    if (!limit) {
	        return string.toString().split(delimiter.toString());
	    } 
	    else 
	    {
	        // support for limit argument
	        var splitted = string.toString().split(delimiter.toString());
	        var partA = splitted.splice(0, limit - 1);
	        var partB = splitted.join(delimiter.toString());
	        partA.push(partB);
	        return partA;
	    }
	}
	

